﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Main_Inventory_DCInward_DeliveryAdd : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string lid = "";
    string rettextboxid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["suppid"] != null && Request.QueryString["returnTextbox"] != null)
        {
            lid = Request.QueryString["suppid"].ToString();
            rettextboxid = Request.QueryString["returnTextbox"].ToString();

           
        }
       // if (!IsPostBack)
       // {
            bindDeliveryAdd();
        //}
        if (((HiddenField)form1.FindControl("hidadd")) != null)
        {
            lblMsg.Text = ((HiddenField)form1.FindControl("hidadd")).Value.ToString();
        }
    }

    protected void bindDeliveryAdd()
    {
        lblMsg.Text = "";
        SqlParameter[] parrr = { 
                                 new SqlParameter("@ledid",lid)
                               };
        DataTable dtdeladd = DU.getdatausingprocedure("usp_get_deliveryadd_by_ledid", parrr);
        if (dtdeladd.Rows.Count > 0)
        {
            maindiv.Visible = true ;
            for (int i = 0; i < dtdeladd.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();

                HiddenField hidadd = new HiddenField();
                hidadd.ID = "hidadd" + i.ToString();

                

                cell1.Align = "Center";
                RadioButton rb1 = new RadioButton();
                rb1.ID = "rb"+i.ToString();
                rb1.CheckedChanged += new EventHandler(rb1_CheckedChanged);
                if (i == 0)
                {
                    rb1.Checked = true;
                }
                rb1.GroupName = "back";
                rb1.CausesValidation = false;
                rb1.Attributes.Add("onclick", "single('" + "rb" + i.ToString() + "','"+i.ToString()+"');");
                cell1.Controls.Add(rb1);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                TextBox txttitle = new TextBox();
                txttitle.ID = "txttitle" + i.ToString();
                txttitle.Text = dtdeladd.Rows[i]["Title"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["Title"].ToString()+", ";

                HiddenField hid_del_id = new HiddenField();
                hid_del_id.ID = "hid_del_id" + i.ToString();
                hid_del_id.Value = dtdeladd.Rows[i]["deliveryaddid"].ToString();

                cell2.Controls.Add(txttitle);
                cell2.Controls.Add(hid_del_id);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                TextBox txtname = new TextBox();

                txtname.ID = "txtname" + i.ToString();
                txtname.Text = dtdeladd.Rows[i]["contactname"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["contactname"].ToString() + "\n";
                cell3.Controls.Add(txtname);

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                TextBox txtadd1 = new TextBox();
                txtadd1.ID = "txtadd1" + i.ToString();
                txtadd1.Text = dtdeladd.Rows[i]["add1"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["add1"].ToString() + " ";
                cell4.Controls.Add(txtadd1);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                TextBox txtadd2 = new TextBox();
                txtadd2.ID = "txtadd2" + i.ToString();
                txtadd2.Text = dtdeladd.Rows[i]["add2"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["add2"].ToString() + " ";
                cell5.Controls.Add(txtadd2);

                HtmlTableCell cell6 = new HtmlTableCell();
                cell6.Align = "Center";
                TextBox txtadd3 = new TextBox();
                txtadd3.ID = "txtadd3" + i.ToString();
                txtadd3.Text = dtdeladd.Rows[i]["add3"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["add3"].ToString() + " ";
                cell6.Controls.Add(txtadd3);

                HtmlTableCell cell7 = new HtmlTableCell();
                cell7.Align = "Center";
                TextBox txtpincode = new TextBox();
                txtpincode.ID = "txtpincode" + i.ToString();
                txtpincode.Text = dtdeladd.Rows[i]["pincode"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["pincode"].ToString() + "\n  ";
                cell7.Controls.Add(txtpincode);

                HtmlTableCell cell8 = new HtmlTableCell();
                cell8.Align = "Center";
                TextBox txtstate = new TextBox();
                txtstate.ID = "txtstate" + i.ToString();
                txtstate.Text = dtdeladd.Rows[i]["state"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["state"].ToString() + "\n  ";
                cell8.Controls.Add(txtstate);

                HtmlTableCell cell9 = new HtmlTableCell();
                cell9.Align = "Center";
                TextBox txtcountry = new TextBox();
                txtcountry.ID = "txtcountry" + i.ToString();
                txtcountry.Text = dtdeladd.Rows[i]["country"].ToString();
                hidadd.Value += dtdeladd.Rows[i]["country"].ToString() + " ";
                cell9.Controls.Add(txtcountry);

                cell1.Controls.Add(hidadd);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);
                row1.Cells.Add(cell6);
                row1.Cells.Add(cell7);
                row1.Cells.Add(cell8);
                row1.Cells.Add(cell9);

                tbladd.Rows.Add(row1);

                hid_hold.Value = hidadd.Value.ToString();
            }
        }
        else
        {
            maindiv.Visible = false;
            lblMsg.ForeColor = System.Drawing.Color.Red;
            lblMsg.Text = "No Address Found...!";
        }
    }

    void rb1_CheckedChanged(object sender, EventArgs e)
    {
      
    }

}
